//
//  RewardController.m
//  LiquorChain
//
//  Created by apple on 2018/12/28.
//  Copyright © 2018年 王冬. All rights reserved.
//

#import "RewardController.h"
#import "RewardViewCell.h"
@interface RewardController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (nonatomic,strong) UICollectionView *collectionView;
@end

@implementation RewardController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"大师奖励";
    self.view.backgroundColor =[UIColor groupTableViewBackgroundColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"邀请规则" style:UIBarButtonItemStyleDone target:self action:@selector(guize)];
    
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor grayColor]];
    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateNormal];

    [self creatView];
    // Do any additional setup after loading the view.
}
-(void)creatView{
    UIImageView *headView =[[UIImageView alloc]init];
    headView.backgroundColor = RGBA(0, 0, 0, 1);
    [self.view addSubview:headView];
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(kNavBarHeight);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(200);
    }];
    UILabel *topLabel =[[UILabel alloc]init];
    [headView addSubview:topLabel];
    topLabel.text = @"邀请朋友有奖励";
    topLabel.textAlignment = NSTextAlignmentCenter;
    topLabel.font =[UIFont systemFontOfSize:34];
    [topLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:34]];
    topLabel.textColor = RGBA(252, 224, 32, 1);
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(35);
        make.left.mas_equalTo(60);
        make.right.mas_equalTo(-60);
        make.height.mas_equalTo(32);
    }];
    UILabel *headLabel =[[UILabel alloc]init];
    [headView addSubview:headLabel];
    headLabel.text = @"每邀请1位+10酿力；成为大师后，最高再+25酿力";
    headLabel.textColor =[UIColor whiteColor];
    headLabel.font =[UIFont systemFontOfSize:12];
    headLabel.textAlignment = NSTextAlignmentCenter;
    [headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topLabel.mas_bottom).with.offset(11);
        make.left.mas_equalTo(topLabel.mas_left).with.offset(-19);
        make.right.mas_equalTo(topLabel.mas_right).with.offset(19);
        make.height.mas_equalTo(12);
    }];
    UILabel *bottomLabel =[[UILabel alloc]init];
    [headView addSubview:bottomLabel];
    bottomLabel.layer.borderColor =[UIColor whiteColor].CGColor;
    bottomLabel.layer.borderWidth = 0.8;
    bottomLabel.layer.cornerRadius = 15;
    bottomLabel.textAlignment = NSTextAlignmentCenter;
    bottomLabel.textColor = [UIColor whiteColor];
    bottomLabel.text = @"我的邀请码：U0E99";
    bottomLabel.font =[UIFont systemFontOfSize:14];
    [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(headLabel.mas_bottom).with.offset(24);
        make.left.mas_equalTo(95);
        make.right.mas_equalTo(-95);
        make.height.mas_equalTo(30);
    }];
    UIView *bodyView =[[UIView alloc]init];
    bodyView.backgroundColor =[UIColor whiteColor];
    bodyView.layer.cornerRadius = 10;
    [self.view addSubview:bodyView];
    [bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(kNavBarHeight + 173);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(-10);
    }];
    
//    UIView *aaa =[[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
//    aaa.backgroundColor =[UIColor redColor];
//    [bodyView addSubview:aaa];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    //设置CollectionView的属性
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-30, SCREEN_HEIGHT - 173 -kNavBarHeight -30) collectionViewLayout:flowLayout];
    self.collectionView.backgroundColor =[UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.scrollEnabled = YES;
    [self.view addSubview:self.collectionView];
    //注册Cell
    //[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"maincoll"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"RewardViewCell" bundle:nil] forCellWithReuseIdentifier:@"maincoll"];
    [bodyView addSubview:self.collectionView];
    
    
  
    
    
    
    

    

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 9;
}

//定义每个Cell的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize size = CGSizeMake((SCREEN_WIDTH-30-40)/3,(SCREEN_WIDTH-30-40)/3 +20);
    return size;
}

//定义每个Section的四边间距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 5, 10);//分别为上、左、下、右
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    RewardViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"maincoll" forIndexPath:indexPath];

    if (indexPath.row ==0) {
        cell.headImageView.image =[UIImage imageNamed:@"item"];
    }
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%ld",indexPath.row);
}

-(void)guize{
    NSLog(@"邀请规则");
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
